package org.example.dao;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.ResultType;
import org.apache.ibatis.annotations.Select;
import org.example.domain.MyLog;

import java.util.List;

/**
 * @author Jimmy
 * @version 1.0
 */
public interface LogDao {

    /**
     * 分页查询（含条件）
     * @param log log
     * @return list
     */
    @Select("<script>select id logId,user_name username,ip,time,method,action from ss_sys_log " +
            "where 1=1 " +
            "<if test= 'username != null '> and user_name like concat(concat('%',#{username}),'%') </if>" +
            "<if test= 'ip != null '> and ip like concat(concat('%',#{ip}),'%') </if>" +
            "<if test= 'time != null '> and time like concat(concat('%',#{time}),'%') </if>" +
            "</script>")
    @ResultType(MyLog.class)
    List<MyLog> findByPage(MyLog log);

    /**
     * 查询总条目数（含条件）
     * @param log log
     * @return int
     */
    @Select("<script>select count(*) from ss_sys_log " +
            "where 1=1 " +
            "<if test= 'username != null '> and user_name like concat(concat('%',#{username}),'%') </if>" +
            "<if test= 'ip != null '> and ip like concat(concat('%',#{ip}),'%') </if>" +
            "<if test= 'time != null '> and time like concat(concat('%',#{time}),'%') </if>" +
            "</script>")
    int findTotal(MyLog log);

    /**
     * 添加日志
     * @param log log
     * @return int
     */
    @Insert("insert into ss_sys_log values(#{logId},#{username},#{ip},#{time},#{method},#{action})")
    int addLog(MyLog log);

}
